function Clock(tags,owner) {
    this.finalTime;
    this.continueBtn;
    this.endBtn;
    this.hour = 0;
    this.minutes = 0;
    this.seconds = 0;
    this.msec = 0;
    this.box;
    this.timebox;
    this.tags = tags;
    this.timer;
    this.beginBtn;
    this.isGo = false;
    this.owner = owner;

    this.createClock();
    this.renderBox();
    var that = this;
    this.beginBtn.addEventListener('click', function () {
        if (!that.isGo) {
            that.Timming();
            that.beginBtn.innerText = '暂停';
            // that.isGo = true;
        } else {
            that.stopTimming();
            that.beginBtn.innerText = '继续';
            // that.isGo = false;
        }
    });
    this.endBtn.addEventListener('click', function () {
        that.clearTimming();
    })
}
Clock.prototype.createClock = function () {
    var box = document.createElement('div');
    box.className = 'boxes';
    var infobox = document.createElement('div');
    infobox.className = 'clockbox';
    var owners = document.createElement('div');
    owners.className = 'owner';
    owners.innerText = this.owner;
    this.timebox = document.createElement('span');
    this.timebox.className = 'timestr';
    this.beginBtn = document.createElement("button")
    this.beginBtn.innerText = '开始';
    this.beginBtn.className = 'beginbtn'
    this.endBtn = document.createElement('button');
    this.endBtn.innerText = '停止';
    this.endBtn.className = 'closebtn';
    infobox.appendChild(this.timebox);
    infobox.appendChild(this.beginBtn);
    infobox.appendChild(this.endBtn);
    box.appendChild(owners);
    box.appendChild(infobox);
    this.tags.appendChild(box);
}
Clock.prototype.renderBox = function () {
    function initnumber(int) {
        return int < 10 ? '0' + int : int + '';
    }
    this.timebox.innerText = '';
    this.timebox.innerText = initnumber(this.hour) + ':' + initnumber(this.minutes) + ':' + initnumber(this.seconds) + ':' + initnumber(this.msec);
}

Clock.prototype.Timming = function () {
    var self = this;
    if(this.isGo) return;
    this.isGo = true;

    function addtime() {
        self.msec++;
        if (self.msec >= 100) {
            self.msec = 0;
            self.seconds++;
            if (self.seconds >= 60) {
                self.seconds = 0;
                self.minutes++;
                if (self.minutes >= 60) {
                    self.minutes = 0;
                    self.hour++;
                }
            }
        }
        self.renderBox();
    }
    this.timer = setInterval(function () {
        addtime();
    }, 10);
};
Clock.prototype.stopTimming = function () {
    var self = this;
    this.isGo = false;
    clearInterval(self.timer);
}
Clock.prototype.clearTimming = function () {
    this.stopTimming();
    this.beginBtn.innerText = '开始';
    this.hour = 0;
    this.minutes = 0;
    this.seconds = 0;
    this.msec = 0;
    this.renderBox();
}